<?php


namespace App\Crontab;


use App\Model\Finance\Util;
use EasySwoole\EasySwoole\Crontab\AbstractCronTask;
use EasySwoole\EasySwoole\Task\TaskManager;

class FinanceTask extends AbstractCronTask
{
    public static function getRule(): string
    {
        // TODO: Implement getRule() method.
        // 定时周期 （每天一次早上10点）
        return '30 15 * * *';

    }

    public static function getTaskName(): string
    {
        // TODO: Implement getTaskName() method.
        // 定时任务名称
        return 'FinanceTask';
    }


    function run(int $taskId, int $workerIndex)
    {
        // TODO: Implement run() method.
        echo('send' . self::getTaskName() . PHP_EOL);
        TaskManager::getInstance()->async(function () {
            GuessTask::sendMsg();
            Util::redpackInit(false);
        });

    }

    function onException(\Throwable $throwable, int $taskId, int $workerIndex)
    {
        // TODO: Implement onException() method.
        echo $throwable->getMessage();
    }
}